<template>
  <div class="app-container">

    <el-table v-loading="loading" :data="examineList">
      <el-table-column label="Id" prop="id" width="50" />
      <el-table-column label="模板Id" prop="auditId" width="100" />
      <el-table-column label="小程序AppID" prop="appId" :show-overflow-tooltip="true" width="200" />
      <el-table-column label="小程序名称" prop="appName" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="上传人" prop="developer" :show-overflow-tooltip="true" width="150" />
      <el-table-column label="版本号" prop="userVersion" :show-overflow-tooltip="true" width="100" />
      <el-table-column label="审核状态" prop="errCode" :show-overflow-tooltip="true" width="100" />
      <el-table-column label="返回信息" prop="errMsg" :show-overflow-tooltip="true" width="300" />
      <el-table-column label="创建时间" align="createTime" prop="createTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleFile(scope.row)"
            v-hasPermi="['wechat:examine:file']"
          >获取体验码</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleSubmit(scope.row)"
            v-hasPermi="['wechat:examine:submit']"
          >提交审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-plus"
            @click="handleReleaes(scope.row)"
            v-hasPermi="['wechat:examine:releaes']"
            v-if="scope.row.errCode == '0'"
          >发布</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="小程序体验二维码" :visible.sync="open" width="500px" append-to-body>
      <el-image :src="imagePath"></el-image>
    </el-dialog>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import { listExamine,testQrcode,releaes,submitTemp } from "@/api/wechat/examine";

  export default {
    name: "TempDraft",
    data() {
      return {
        // 遮罩层
        loading: true,
        //tabs
        activeName: 'first',
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 小程序草稿箱数据
        examineList: [],

        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 是否显示弹出层（数据权限）
        openDataScope: false,
        // 日期范围
        dateRange: [],

        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],

        //二维码url
        imagePath:'',
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          roleName: undefined,
          roleKey: undefined,
          status: undefined
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },

      };
    },
    created() {
      this.getList();
    },
    methods: {

      /** 查询审核列表 */
      getList() {
        this.loading = true;
        listExamine().then(
          response => {
            this.examineList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      /*提交审核*/
      handleSubmit(row){
        const appId = row.appId;
        this.$confirm('是否确认提交appId"' + appId + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          console.log("11111111111")
          let data = {
            id: row.id,
            appId: appId
          }
          return submitTemp(data);
        }).then(() => {
          this.getList();
          this.msgSuccess("提交成功");
        }).catch(function() {});
      },

      //获取体验码
      handleFile(row){
        this.loading = true;
        let params = {"appId":row.appId}
        testQrcode(params).then(
          response => {
            console.log(response)
            this.imagePath = "https://persionbucket.oss-cn-chengdu.aliyuncs.com/"+response.data;
            this.open = true;
            this.loading = false;
          }
        );
      },

      //发布
      handleReleaes(row){
        const appId = row.appId;
        this.$confirm('是否确认发布模板Id"' + appId + '"的小程序?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          let params = {"appId":appId}
          return releaes(params);
        }).then(() => {
          this.getList();
          this.msgSuccess("发布成功");
        }).catch(function() {});
      },

    }
  };
</script>
<style>
  .el-table td, .el-table th{
    text-align: center !important;
  }
</style>
